package com.noble.glamour.ui.agora.act.vfloat;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

/**
 * 音视频悬浮窗Service
 * <p>
 * Created by Su on 2017/7/12.
 */
public class RtcFloatService extends Service implements RtcFloatListener {
    private RtcFloatManager mFloatManager;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (this.mFloatManager != null) {
            return START_STICKY;
        }

        // 添加悬浮窗
        this.mFloatManager = new RtcFloatManager(this, this);
        this.mFloatManager.addFloatingView();

        return START_REDELIVER_INTENT;
    }

    @Override
    public void onDestroy() {
        destroyFloatingView();
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onFinishFloatView() {
        stopSelf();
    }

    /**
     * 销毁悬浮窗
     */
    private void destroyFloatingView() {
        if (this.mFloatManager != null) {
            this.mFloatManager.removeAllFloatingView();
            this.mFloatManager = null;
        }
    }
}
